﻿using HandyControl.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace 功能测试软件.View
{
    /// <summary>
    /// BtLogView.xaml 的交互逻辑
    /// </summary>
    public partial class BtLogView : System.Windows.Window
    {
        private TestView _testView = null;
        public ViewModel.BtLogViewModel viewModel = new ViewModel.BtLogViewModel();
        public BtLogView(TestView testView)
        {
            InitializeComponent();
            _testView = testView;
            DataContext = viewModel;
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            this.Hide();
            e.Cancel = true;
        }

        private void PackIcon_MouseLeave(object sender, MouseEventArgs e)
        {
            Cursor = Cursors.Arrow;
        }

        private void PackIcon_MouseMove(object sender, MouseEventArgs e)
        {
            Cursor = Cursors.Hand;
        }

        private void PackIcon_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (TestView.isScan==false)
                {
                    //清空日志
                    BtLabelBLL.UiBLL.RichTextBoxClearText(RichTextBoxBt);
                    //继续搜索
                    TestView.isScan = true;
                }
            }
            catch (Exception ex) 
            {
                Growl.Error(ex.Message);
                BtLabelTool.LogHelper.WriteLog(ex.ToString());
            }
        }
        public void InitMacs()
        {
            try
            {
                Dispatcher.Invoke(() =>
                {
                    viewModel.MacItems.Clear();
                        for (int i = 0; i < View.TestView.Macs.Count; i++)
                        {
                            ViewModel.BtLogViewModel.MacItem macItem = new ViewModel.BtLogViewModel.MacItem();
                            macItem.BT_MAC = View.TestView.Macs[i].Address;
                            macItem.dBm = View.TestView.Macs[i].DBm;
                            macItem.No = i;
                            viewModel.MacItems.Add(macItem);
                        }
                });
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
    }
}
